<template>
    <lay-card>

        <template v-slot:body>
            <lay-row>
                <lay-col>
                    <lay-table :loading="config.loading" :resize="true" :default-toolbar="true"
                        :columns="config.columns" :page="config.page" @change="change" :data-source="config.data"
                        v-model:selectedKey="config.selectedKey" v-model:selectedKeys="config.selectedKeys"
                        class="project-grids">

                        <template #toolbar>
                            <lay-input v-model="config.search.title" size="sm" placeholder="搜索"
                                suffix-icon="layui-icon-search" style="width: 20%;"></lay-input>

                            <lay-button-group v-for="n in listbutton.toolbarbuttons" :key="n">
                                <lay-button :size="n.size" :type="n.status" :style="'display:'+display(n)" border-style="dashed"
                                    @click="Events(n, null)"> {{ n.name}}</lay-button>
                            </lay-button-group>
                        </template>
                        <template v-slot:operator="{ row }">
                            <span v-for="n in listbutton.rowbuttons" :key="n">
                                <lay-tooltip :content="n.name" position="bottom" :is-dark="true">
                                    <button class="a-button type--button is--circle" circle @click="Events(n, row)">
                                        <lay-icon :type="n.icon" :color="n.color">

                                        </lay-icon>
                                    </button>
                                </lay-tooltip>

                            </span>

                        </template>
             
               
           
                    </lay-table>
                </lay-col>


            </lay-row>
        </template>
    </lay-card>
</template>
<script lang="ts">
export default {
    name: "mianwait"
}
</script>
<script lang="ts" setup>
import { ref, nextTick } from "vue";
import { layer } from "@layui/layer-vue";
import webosutils from 'webosutils';
import { useRoute } from 'vue-router';
import { ReleaseIcon } from '@layui/icons-vue';
import { useRouter } from 'vue-router';
import listurils from '../../utils/listutils';
import { LayerForm} from 'webos-form-design';

const active4 = ref("");


const selectedKeys = ref([]);
const router = useRouter();
const route = useRoute();
const typelist = ref<any>([]);
const listbutton = ref({
    rowbuttons: [] as any,
    toolbarbuttons: [] as any,
});
const size = ref("sm");

const display=(n:any)=>{
   let status= n.status+'';
   
        // -1 删除 0编辑 1上架 2上架中 3已下架 4 售空
   if(status=='0'&&n.name=='编辑'||status=='3'&&n.name=='已下架'){

   }else{
    
   }
   if(status=='0'||status=='2'){

}
    
}

const getstatus=(f:any)=>{
    f=f+"";
    switch (f){
        // -1 删除 0编辑 1上架 2上架中 3已下架 4 售空
        case '-1':
            return '删除';
        case '0':
            return '编辑';
        case '1':
            return '上架';
        case '2':
            return '上架中';
        case '3':
            return '已下架';
        case '4':
            return '售空';
        default:
            return '未知';
    }
}
const config = ref({
    loading: true,
    data: [],
    page: {
        total: 0,
        limit: 10,
        current: 1,
        showRefresh: true,
        limits: [5, 10, 20, 50, 100, 200]
    },
    selectedKey:"",
    selectedKeys:[],
    columns: [
    { title: "选项", width: "55px", type: "checkbox", fixed: "left" },
        { key: 'addressdetails', title: '送餐点', ellipsisTooltip: true, },
        { key: 'name', title: '姓名', ellipsisTooltip: true },
        { key: 'phone', title: '电话', ellipsisTooltip: true },
        

        {
            title: "操作",

            fixed: "right",
            customSlot: "operator",
            key: "operator",
            ignoreExport: true
        }
    ],
    api: "",
    search: {
        type: route.query.zhuanti,
        title: ""
    }
});
const signleImg = (row:any)=> {
    layer.photos({
      imgList:[{src:row.img,alt:row.title}]
    })
}

listurils.getButton(route.query.appid, config, listbutton).then((res: any) => {
    //加载完成后刷新列表

    if (res.success) {
        config.value.api = res.data.api;
        if (listbutton.value.toolbarbuttons.length > 0) {
            size.value = listbutton.value.toolbarbuttons[0].size;
        }
        listurils.searchEvent(config);
    } else {
        layer.notify({
            title: "Error",
            content: res.msg,
            icon: 2
        })
    }

});
const change = (p: any) => {

    config.value.page.current = p.current;
    config.value.page.limit = p.limit;
    listurils.searchEvent(config);
}
const Callback = () => {
    listurils.searchEvent(config);
}
const Events = (ent: any, row: any) => {
    try {

        switch (ent.events) {
            case "editEvent":
                if (ent.ispopup == 0) {
                    var query = new Object() as any;
                    query.fromid = ent.formid;
                    query.instanceid = row.id;
                   // query.zhuanti = row.classid;
                    query.tabname = encodeURIComponent(row.title);
                    router.push({ path: "/formdesign/submitfrom", query: query })


                } else {
                    listurils.editRowEvent(LayerForm, ent, row, { fromid: ent.formid, instanceid: row.id, callback: Callback }, {});

                }
                break;
            case "searchEvent":
                if (config.value.page) {
                    listurils.searchEvent(config);
                }

                break;
            case "deleteEvent": listurils.removeRowEvent(ent, row, listurils.searchEvent, config);
                break;
            case "addEvent":
                if (ent.ispopup == 0) {
                    var query = new Object() as any;
                    query.fromid = ent.formid;
                    query.instanceid = "";
                    query.zhuanti = route.query.zhuanti;
                    query.tabname = encodeURIComponent(ent.title);
                    router.push({ path: ent.api, query: query })

                } else {
                    listurils.addEvent(LayerForm, ent, { fromid: ent.formid, instanceid: "", callback: Callback }, {});

                }
                break;

            case "previewEvent": listurils.previewEvent(LayerForm, ent, row);
                break;
            case "SelectEvent":
                listurils.SelectEvent(ent, row, listurils.searchEvent, config);
                break;
        }
    } catch (e) {
        layer.msg("按钮解析失败", { icon: 3, time: 1000 })
    }

}

</script>
<style scoped></style>